package com.fotkidemo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
import com.fotkidemo.util.AuthUtil;

/**
 * Created with IntelliJ IDEA.
 * User: roma
 * Date: 6/26/12
 * Time: 10:28 PM
 * To change this template use File | Settings | File Templates.
 */

//Получение access_token от oauth-серевера yandex'а.
public class ReceiveTokenActivity extends Activity {
    private static final String TAG = "ReceiveTokenActivity";

    @Override
    protected void onResume() {
        super.onResume();
        Uri uri = getIntent().getData();

        if (BuildConfig.DEBUG)
            Log.d(TAG, "got uri...");

        if (uri != null) {
            if (BuildConfig.DEBUG)
                Log.d(TAG, "get uri- success: " + uri);

            String access_token = uri.getFragment().split("&")[0].split("=")[1];
            AuthUtil.saveAccessToken(this, access_token);

            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
        } else {
            if (BuildConfig.DEBUG)
                Log.d(TAG, "get uri- failure");

            Toast.makeText(this, "access token is null", Toast.LENGTH_LONG).show();

            Intent intent = new Intent(this, LoginActivity.class);
            startActivity(intent);
        }
    }
}